<?php
// +----------------------------------------------------------------------
// | zhanshop-cloud / TestLogstash.php    [ 2025/1/7 16:15 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2025 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangqiquan <768617998@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\console;

use zhanshop\App;
use zhanshop\console\Command;
use zhanshop\console\Input;
use zhanshop\console\Output;
use zhanshop\client\Httpclient;
use zhanshop\util\WebHook;

class TestLogstash extends Command
{
    public function configure(){
        $this->useCache()->setTitle('test')->setDescription('测试写入日志采集');
    }

    public function execute(Input $input, Output $output)
    {
        $url = 'http://'.App::config()->get('bridge.ip').':'.(intval(App::config()->get('bridge.port')) - 1).'/v1/cloud.log/'.App::config()->get('bridge.token');
        $httpclient = new Httpclient();
        $httpclient->enableIpv6()->setTimeout(3000);
        $ok = $httpclient->setHeader('Content-Type', 'application/json')->request($url, "POST", json_encode([
            'path' => "test/".time(),
            'body' => '{"timestamp":"2025-01-07T16:33:32+08:00","server_addr":"172.18.0.2","remote_addr":"127.0.0.1","host":"127.0.0.1","uri":"/v2/test","body_bytes_sent":495,"request":"GET /v2/test HTTP/1.1","request_length":1332,"request_time":0.087,"status":"200","http_referer":"","http_user_agent":"Mozilla/5.0"}',
        ]));
        var_dump($ok);

        App::make(WebHook::class)->bridge("测试推送");
    }
}